package Ventanas.usuario;



import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

import Ventanas.admin.PanelInicialA;

public class PanelInicial extends JPanel implements ActionListener{
	private Ventana ventana;
	private JButton bConectar;
	
	private JLabel lIPserv;
	private JTextField tIPserv;
	
	private JLabel fondo;
	//private PanelUsuario panelUsuario;
	
	public PanelInicial(Ventana v){

		ventana = v;
		ventana.pack();
		ventana.setLocationRelativeTo(null);
		ventana.setVisible( true );
		ventana.getContentPane().add( this, "Center" );
		ventana.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		lIPserv = new javax.swing.JLabel();
		tIPserv = new javax.swing.JTextField();
		bConectar = new javax.swing.JButton();
		fondo = new JLabel();

		setVisible(true);

		setLayout(null);
		
		lIPserv.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
		lIPserv.setForeground(new java.awt.Color(255, 255, 255));
		lIPserv.setText("IP servidor");
		add(lIPserv);
		lIPserv.setBounds(195, 260, 90, 25);
		
		add(tIPserv);
		tIPserv.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
		tIPserv.setBounds(312, 260, 210, 30);
		tIPserv.setText("127.0.0.1");
		tIPserv.setForeground(new java.awt.Color(255, 255, 255));
		tIPserv.setBackground(new Color(6, 52, 72));

		bConectar.setText("Conectar");
		
		add(bConectar);
		bConectar.setFont(new java.awt.Font("Comic Sans MS", 0, 14));
		bConectar.setBounds(540, 260, 90, 30);
		bConectar.addActionListener(this);
		
		this.setBackground(new Color(3, 41, 51));
		
		fondo.setIcon(new ImageIcon("src/resources/onda.png"));
		add(fondo);
		fondo.setBounds(155, 10, 516, 290);
	}
	
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getSource()==(bConectar))
		{
			boolean conexion = ventana.conectar(tIPserv.getText());
			if(conexion)
			{
				this.setVisible(false);
				PanelUsuario panel = new PanelUsuario();
				ventana.getContentPane().add(panel,0);
				panel.setVisible(true);
			}
			else
			{
				tIPserv.setText("");
			}
		}
		
	}

	
	public static void main(String [] args){
		//Look & Feel Nimbus
		for(UIManager.LookAndFeelInfo laf:UIManager.getInstalledLookAndFeels()){
			if("Nimbus".equals(laf.getName()))
				try {
					UIManager.setLookAndFeel(laf.getClassName());
				} catch (Exception ex) {
				}
		}
		new Ventana();
	}
	
}

